package com.example.module_home.vm

import android.util.Log
import com.example.lib_common.view.vm.BaseViewModel
import com.example.module_home.api.HomeApiServer
import com.example.module_home.entity.NoticeEntity
import com.example.module_home.entity.NoticeEntityItem
import com.example.module_home.model.HomeRepository
import com.example.module_home.model.HomeResultData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class NoticeViewModel @Inject constructor(
    private val apiServer: HomeApiServer):
    BaseViewModel<HomeRepository,HomeResultData<NoticeEntity>>() {

    fun getListData(page: Int, size: Int) {

        mViewModelScope.launch(mDispatcher) {
            try {
                val resultData = apiServer.getNotice(page, size)
                val res = HomeResultData(
                    state = resultData.state,
                    msg = resultData.msg,
                    data = resultData.data
                )
                mSuccessLiveData.postValue(res)
            } catch (e: Exception) {

                Log.d("公告列表请求失败", e.message.toString())
            }
        }
    }
}
